package 算法学习计划;

public class 二分查找 {

    public static int search(int[] nums, int target){
        int mid = nums.length / 2;
        int start = 0;
        int end = nums.length - 1;
        while (end >= start){

            if (nums[mid] == target){
                return mid;
            }
            if (nums[mid] > target){
                end = mid - 1;
                mid = (end - start)/ 2;
            }else {
                start = mid + 1;
                mid = start + ((end - start)/ 2);
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,3,7,23,45};
        System.out.println(search(nums,45));
    }
}
